//
//  MusicViewController.m
//  XMLY
//
//  Created by 曾杰 on 15/11/4.
//  Copyright © 2015年 曾杰. All rights reserved.
//

#import "MusicViewController.h"
#import "YKPageView.h"
#import "MusicViewCell.h"
#import "MusicTableViewController.h"
#import "MusicRecommendTableViewController.h"
@interface MusicViewController ()<YKPageViewDataSource,YKPageViewDelegate>
@property (nonatomic, strong) NSArray *items;
@property (nonatomic, weak) YKPageView *pageView;
@property (nonatomic, strong)MusicTableViewController * muiscVC;
@property (nonatomic, strong)MusicRecommendTableViewController * remmendVC;
@end

@implementation MusicViewController
- (NSArray *)items {
    if (_items == nil) {
        _items = @[@"推荐", @"精选", @"独创", @"翻唱", @"主播|节目", @"排行", @"明星", @"怀旧", @"电影|原声", @"动慢|游戏",@"禅音",@"催眠",@"儿童",@"华语|粤语",@"日语韩语",@"欧美",@"器乐",@"安静",@"伤感",@"午后",@"纯音乐"];
    }
    return _items;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    [self p_addPageView];
  
    // Do any additional setup after loading the view.
}

- (void)p_addPageView {
    YKPageView *pageView = [[YKPageView alloc] initWithFrame:CGRectMake(0, 70, self.view.bounds.size.width, self.view.bounds.size.height-70)];
    pageView.dataSource = self;
    pageView.delegate = self;
    pageView.selectIndex = 0;
    pageView.menuViewStyle = YKMenuViewStyleLine;
    [self.view addSubview:pageView];
    self.pageView = pageView;
    
}

#pragma mark - page view datasource
// Menu的标题用NSArray封装，内为NSString
- (NSArray *)menuItemsForMenuViewInPageView:(YKPageView *)pageView {
    return self.items;
}

- (YKPageCell *)pageView:(YKPageView *)pageView cellForIndex:(NSInteger)index {
    static NSString *identifier = @"pageCell";
   YKPageCell *cell = [pageView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[YKPageCell alloc] initWithIdentifier:identifier];
    }
    
    cell.backgroundColor = [UIColor whiteColor];
      _muiscVC = [[MusicTableViewController alloc]init];
  
      switch (index) {
        case 0:{
            
            _remmendVC = [[MusicRecommendTableViewController alloc]init];
            [cell addSubview:_remmendVC.tableView];
        }
            
            break;
            case 1:
        {
        
            
            _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E7%B2%BE%E9%80%89%7C%E6%AD%8C%E5%8D%95";
             [cell addSubview:_muiscVC.view];

            
        }
            break;
            case 2:
        {
             _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=android&pageId=1&pageSize=20&status=0&tagName=%E5%8E%9F%E5%88%9B%7C%E7%8B%AC%E7%AB%8B";
             [cell addSubview:_muiscVC.view];
            
        }break;
            case 3:
        {
        
            _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E7%BF%BB%E5%94%B1%7C%E7%BF%BB%E5%A5%8F";
                [cell addSubview:_muiscVC.view];
            
            
        }
            break;
              case 4:
          {
              _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E4%B8%BB%E6%92%AD%7C%E8%8A%82%E7%9B%AE";
               [cell addSubview:_muiscVC.view];
              

          }
              break;
             
              case 5:
          {
          _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E6%A6%9C%E5%8D%95%7C%E6%8E%92%E8%A1%8C";
               [cell addSubview:_muiscVC.view];
            }
              break;
              case 6:
          {
          _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E8%89%BA%E4%BA%BA%7C%E6%98%8E%E6%98%9F";
              [cell addSubview:_muiscVC.view];

          }
              break;
              
              case 7:
          {
          _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E6%80%80%E6%97%A7%7C%E7%BB%8F%E5%85%B8";
               [cell addSubview:_muiscVC.view];
          }
              break;
              case 8:
          {
          _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E7%94%B5%E5%BD%B1%7C%E5%8E%9F%E5%A3%B0";
               [cell addSubview:_muiscVC.view];
          }
              break;
              
              case 9:
          {
          _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E5%8A%A8%E6%BC%AB%7C%E6%B8%B8%E6%88%8F";
               [cell addSubview:_muiscVC.view];
          }
              break;
              case 10:
          {
              _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E4%BD%9B%E6%95%99%7C%E7%A6%85%E9%9F%B3";
               [cell addSubview:_muiscVC.view];

          }
              break;
              case 11:
          {
              _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E5%82%AC%E7%9C%A0%7C%E8%A7%A3%E5%8E%8B";
               [cell addSubview:_muiscVC.view];

          }
              break;
              case 12:
          {
              _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E5%84%BF%E7%AB%A5%7C%E8%83%8E%E6%95%99";
               [cell addSubview:_muiscVC.view];

          }
              break;
              case 13:
          {
              _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E5%8D%8E%E8%AF%AD%7C%E7%B2%A4%E8%AF%AD";
               [cell addSubview:_muiscVC.view];

          }
              break;
              case 14:
          {
          _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E6%97%A5%E8%AF%AD%7C%E9%9F%A9%E8%AF%AD";
               [cell addSubview:_muiscVC.view];
          }
              break;
              case 15:
          {
              _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E6%AC%A7%E7%BE%8E%7C%E5%85%B6%E4%BB%96";
              [cell addSubview:_muiscVC.view];


          }
              break;
              case 16:
          {
              _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E5%99%A8%E4%B9%90%7C%E5%BC%B9%E5%A5%8F";
               [cell addSubview:_muiscVC.view];

          }
              break;
              case 17:
          {
              _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E7%9D%A1%E5%89%8D.%E5%AE%89%E9%9D%99";
               [cell addSubview:_muiscVC.view];

          }
              break;
              case 18:
          {
              _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E5%AD%A4%E5%8D%95.%E4%BC%A4%E6%84%9F";
               [cell addSubview:_muiscVC.view];

          }
              break;
              case 19:
          {
              _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%E5%8D%88%E5%90%8E.%E5%92%96%E5%95%A1";
               [cell addSubview:_muiscVC.view];

          }
              break;
              case 20:
          {
              _muiscVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=2&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%7C%E7%BA%AF%E9%9F%B3%E4%B9%90%7C";
               [cell addSubview:_muiscVC.view];

          }
              break;
         
    }

       return cell;
}
#pragma mark Page view delegate
// 若不实现，默认红黑，为保证字体颜色渐变，请尽量选用RGBA来创建UIColor
- (UIColor *)titleColorOfMenuItemInPageView:(YKPageView *)pageView withState:(YKMenuItemTitleColorState)state {
    //    return [UIColor randomColor];
    return [UIColor whiteColor];
}

// 若不实现,默认为30
- (CGFloat)pageView:(YKPageView *)pageView heightForMenuView:(YKMenuView *)menuView{
    return 30;
}

// 若不实现，默认为15/18
- (CGFloat)titleSizeOfMenuItemInPageView:(YKPageView *)pageView withState:(YKMenuItemTitleSizeState)state {
    switch (state) {
        case YKMenuItemTitleSizeStateNormal:
            return 15;
            break;
        case YKMenuItemTitleSizeStateSelected:
            return 18;
        default:
            break;
    }
}

// 若不实现，默认为灰色
- (UIColor *)backgroundColorOfMenuViewInPageView:(YKPageView *)pageView {
    return [UIColor lightGrayColor];
}

// MenuView 内部各个 item 的宽度，若标题过长可自行设置，默认为 60
- (CGFloat)pageView:(YKPageView *)pageView widthForMenuItemAtIndex:(NSInteger)index {
    return 100;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
